home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c
- Subject: Re: Stylistic Concerns with Header Files
- Date: Sun, 21 Apr 1996 14:36:41 GMT
- Organization: Netcom
- Message-ID: <317a471b.42264192@nntp.ix.netcom.com>
- References: <4lb9bl$amo@wormer.fn.net>
- NNTP-Posting-Host: ix-dc19-08.ix.netcom.com
- X-NETCOM-Date: Sun Apr 21 9:36:00 AM CDT 1996
- X-Newsreader: Forte Agent .99d/32.182
-
- withheld@keepitpublic.com (Rusty Meathook) wrote:
-
- > I occasionally create the undesirable situation of having to include
- > my header files in a certain order, or having to include one header
- > file to include another, and I was wondering how I can circumvent
- > that. The most common case is something like this:
- >
- > /* Untested code; call this "foo.h" */
- >
- > #ifndef _FOO_H_
- > #define _FOO_H_
- >
- > typedef struct price_tag
- > {
- > float cost;
- > BARCODE code;
- > struct price_tag *next;
- > } PRICE_INFO;
- >
- > #endif
- >
- > /* */
- >
- > /* Untested code; call this "bar.h" */
- >
- > #ifndef _BAR_H_
- > #define _BAR_H_
- >
- > typedef struct barcode_tag
- > {
- > char number;
- > } BARCODE;
- >
- > #endif
- >
- > /* */
- >
- > Of course, these are intentionally simple examples, and there are
- > obvious ways to solve the problem by merging the two header files.
- > Imagine, however, that it is undesirable to merge the header files --
- > each of them deals with a different library of functions, and need to
- > be kept seperate to maintain modularity.
- >
- > The obvious problem, now, is that a source file that needs to use
- > "foo.h" will have to include "bar.h" prior to including "foo.h", which
- > is a nasty situation stylistically. Including another header file
- > within a header file is even worse.
- >
- > My question is: how can you keep the two header files seperate, and
- > still get away with not having header file dependancies or inclusion
- > orders?
-
- Why is including another header file in a header file worse? It's
- often the appropriate solution. That's what I'd do here.
-
- Note that names beginning with an underscore and an upper case letter
- are reserved for use by the implementation. You should not define
- such names yourself. Use something like FOO_H instead.
-
- Michael M Rubenstein
-